package com.atbeijing.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark06_Oper_Transform {

    def main(args: Array[String]): Unit = {

        val conf = new SparkConf().setMaster("local[*]").setAppName("TransformOperator")
        val sc = new SparkContext(conf)

        // TODO 算子 - 转换 - groupBy
        val rdd : RDD[Int] = sc.makeRDD(
            List(1,2,3,4),2
        )

        // Int(元素) => 规则 => K（组名）
        val rdd1 = rdd.groupBy(
            num => {
                if ( num % 2 == 0 ) {
                    "偶数"
                } else {
                    "奇数"
                }
//                num % 2
            }
        )

        rdd1.collect().foreach(println)




        sc.stop()

    }
}
